package j07contains;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

class Cat{
    String name;
    int age;

    public Cat(String name, int age) {
        this.name = name;
        this.age = age;
    }

//    @Override
//    public boolean equals(Object obj) {
//        return true;
//    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Cat cat = (Cat) o;
        return age == cat.age && Objects.equals(name, cat.name);
    }
}

public class J1 {
    public static void main(String[] args) {
        List<Cat> l1 = new ArrayList<>();
        l1.add(new Cat("tom",2));

        boolean isHave = l1.contains(
                new Cat("tom",21)
        );
        System.out.println(isHave);//false

        Cat c1 = new Cat("加菲猫",3);
        Cat c2 = new Cat("加菲猫2",3);
        System.out.println(c1.equals(c2));//false
    }
}
